Shader "Unlit/VertexAnimation"
{
  Properties
    {
        _MainTex("Main Tex", 2D) = "white" {}
		_Color("Color", Color) = (1, 1, 1, 1)
		_Magnitude("Distortion Magnitude", Float) = 1               //水波幅度
 		_Frequency("Distortion Frequency", Float) = 1               //水波频率
 		_InvWaveLength("Distortion Inverse Wave Length", Float) = 10        //水波平缓程度（波幅倒数）
 		_Speed("Speed", Float) = 0.5                //河流速度
    }
    SubShader
    {
        LOD 200
        Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "DisableBatching" = "True" }
        //DisableBatching标签：设置为True后就不会对此Shader相关的模型进行批处理
        //这是因为我们在顶点着色器中修改了模型空间下物体的顶点，而批处理本质上是将多个物体合成一个物体的逻辑，这样对于单个模型就失去它的模型空间了
        PASS
        {
            Tags { "LightMode" = "ForwardBase" }
            ZWrite Off Cull Off
            Blend SrcAlpha OneMinusSrcAlpha
 
            CGPROGRAM
            #pragma vertex vert             //声明顶点着色器的函数
            #pragma fragment frag           //声明片段着色器的函数
            #include "UnityCG.cginc"
            #include "Lighting.cginc"
 
            sampler2D _MainTex;
			fixed4 _Color;
			float _Magnitude;
			float _Frequency;
			float _InvWaveLength;
			float _Speed;
 
            float4 _MainTex_ST;
            struct _2vert 
            {
                float4 vertex: POSITION;
                float4 texcoord: TEXCOORD0;
            };
            struct vert2frag 
            {
                float4 pos: SV_POSITION;
                float2 uv: TEXCOORD0;
            };
 
            vert2frag vert(_2vert v) 
            {
				float4 offset;
				offset = float4(0.0, 0.0, 0.0, 0.0);
				offset.x = sin(_Frequency * _Time.y + v.vertex.x * _InvWaveLength + v.vertex.y * _InvWaveLength + v.vertex.z * _InvWaveLength) * _Magnitude;
 
                vert2frag o;
                o.pos = UnityObjectToClipPos(v.vertex + offset);
                o.uv = TRANSFORM_TEX(v.texcoord, _MainTex) + float2(0.0, _Time.y * _Speed);
                return o;
            }
            fixed4 frag(vert2frag i): SV_Target 
            {
                fixed4 color = tex2D(_MainTex, i.uv);
				color.rgb *= _Color.rgb;
				return color;
            } 
            ENDCG
        }
    }
    FallBack "Transparent/VertexLit"
}